package commands

import (
	"github.com/yourusername/virt-manager-go/internal/sdk"
)

// ClientManager 管理 SDK 客户端实例
var ClientManager *clientManager

type clientManager struct {
	clients map[string]*sdk.Client
}

// InitClientManager 初始化客户端管理器
func InitClientManager() {
	ClientManager = &clientManager{
		clients: make(map[string]*sdk.Client),
	}
}

// GetClient 获取指定服务器地址的客户端
func (cm *clientManager) GetClient(serverURL string) *sdk.Client {
	if client, exists := cm.clients[serverURL]; exists {
		return client
	}

	// 创建新的客户端
	client := sdk.NewClient(serverURL)
	cm.clients[serverURL] = client
	return client
}
